package com.test.deencredit.view_deencredit;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.test.deencredit.R;

public class NumberTextView_S_deencredit extends RelativeLayout {

    private Context mContext_deencredit;

    private CharSequence text_deencredit;

    private LinearLayout groupLayout_deencredit;

    public NumberTextView_S_deencredit(Context context) {
        super(context);
        initView_deencredit(context,null);
    }

    public NumberTextView_S_deencredit(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView_deencredit(context, attrs);
    }

    public NumberTextView_S_deencredit(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView_deencredit(context, attrs);
    }

    private void initView_deencredit(Context context, AttributeSet attrs){

        mContext_deencredit = context;

        if (attrs!=null){
            @SuppressLint("Recycle") TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NumberTextView_S_deencredit);
            text_deencredit = typedArray.getText(R.styleable.NumberTextView_S_deencredit_android_text);
        }

        View view = View.inflate(context,R.layout.view_number_text_deencredit,this);
        groupLayout_deencredit = view.findViewById(R.id.tvn_layout_group);

        if (text_deencredit == null) text_deencredit = "";

        setText_deencredit(text_deencredit);

    }

    public void setText_deencredit(CharSequence text_deencredit){
        this.text_deencredit = text_deencredit;
        groupLayout_deencredit.removeAllViews();

        for (int i = 0; i< text_deencredit.length(); i++){
            char c = text_deencredit.charAt(i);
            addChar_deencredit(c);
        }
    }

    private void addChar_deencredit(char c){
        View view = View.inflate(mContext_deencredit,R.layout.view_bg_number_s_deencredit,null);
        TextView charTv = view.findViewById(R.id.vbn_tv_char);
        charTv.setText(String.valueOf(c));
        groupLayout_deencredit.addView(view);
    }


}
